using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;
using Inventory.Domain.Models;

namespace Inventory.Database.Mapping
{
    public class MoviesMovieGenreMap : EntityTypeConfiguration<MoviesMovieGenre>
    {
        public MoviesMovieGenreMap()
        {
            // Primary Key
            this.HasKey(t => t.Id);

            // Properties
            // Table & Column Mappings
            this.ToTable("MoviesMovieGenres");
            this.Property(t => t.Id).HasColumnName("Id");
            this.Property(t => t.MovieId).HasColumnName("MovieId");
            this.Property(t => t.GenreId).HasColumnName("GenreId");
            this.Property(t => t.MovieGenre_Id).HasColumnName("MovieGenre_Id");

            // Relationships
            this.HasOptional(t => t.MovieGenre)
                .WithMany(t => t.MoviesMovieGenres)
                .HasForeignKey(d => d.MovieGenre_Id);
            this.HasRequired(t => t.Movie)
                .WithMany(t => t.MoviesMovieGenres)
                .HasForeignKey(d => d.MovieId);

        }
    }
}
